home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / midi / gfft.lha / gfft-2.03 / source / gfft-2.03-source.lha / oksigma.c < prev    next >
C/C++ Source or Header  |  1996-01-02  |  2KB  |  55 lines

  1. /***************************************************************************
  2.  *          Copyright (C) 1994  Charles P. Peterson                  *
  3.  *         4007 Enchanted Sun, San Antonio, Texas 78244-1254             *
  4.  *              Email: Charles_P_Peterson@fcircus.sat.tx.us                *
  5.  *                                                                         *
  6.  *          This is free software with NO WARRANTY.                  *
  7.  *          See gfft.c, or run program itself, for details.              *
  8.  *              Support is available for a fee.                      *
  9.  ***************************************************************************
  10.  *
  11.  * Program:     gfft--General FFT analysis
  12.  * File:        oksigma.c
  13.  * Purpose:     Sum new processed values into 'bins' for later normalization
  14.  * Author:      Charles Peterson (CPP)
  15.  * History:     23-August-1993 CPP; Created.
  16.  * Comment:     Bins are assumed to have been zeroed prior to first use.
  17.  *              No normalization (even to correct for one-sidedness)
  18.  *              is performed here; power spectrum (squared amplitude)
  19.  *              is assumed.
  20.  *
  21.  *              Mathematical synopsis:
  22.  *              The power spectrum for each bin is magnitude(Hf) ** 2
  23.  *                (for one-sided, it is actually 2 * magnitude (Hf) ** 2).
  24.  *              However, the magnitude of the complex number (a,b) is
  25.  *                sqrt (a**2 + b**2), so, the power spectrum for a bin
  26.  *                where Hf is (a,b) is a**2 + b**2.
  27.  */
  28.  
  29. #ifdef _AMIGA
  30. #ifdef _M68881
  31. #include <m68881.h>
  32. #endif
  33. #endif
  34.  
  35. #include "gfft.h"
  36.  
  37. void ok_sigma (float *indata, BIN_TYPE *bins, unsigned long number_bins)
  38. {
  39.     unsigned long i;
  40.     unsigned long last_bin_index = number_bins; /* - 1 + 1 for 0 Hz */
  41. /*
  42.  * deal with 'packed' real (non-complex) values for f=0 and f=fc
  43.  */
  44.     bins[0] += indata[0] * indata[0];
  45.     bins[last_bin_index] += indata[1] * indata[1];
  46.  
  47.     indata += 2;
  48.  
  49.     for (i = 1; i < last_bin_index; i++)
  50.     {
  51.     bins[i] += indata[0] * indata[0] + indata[1] * indata[1];
  52.     indata += 2;
  53.     }
  54. }
  55.